<template>
  <div class="channelDetails">
    <div class="details-top">
      <van-tabs v-model="active" @click="tabFn">
        <van-tab
          v-for="item in brotherCategory"
          :title="item.name"
          :key="item.id"
        >
        </van-tab>
      </van-tabs>
    </div>
    <div class="details_bottom">
      <h3 class="channel_title">{{ currentCategory.name }}</h3>
      <p class="channel_sub_title">{{ currentCategory.front_desc }}</p>
      <ul>
        <li v-for="item in goodsList" :key="item.id" @click="onClick(item.id)">
          <img :src="item.list_pic_url" width="100%" alt="" />
          <div>{{ item.name }}</div>
          <p>{{ item.retail_price | filterMoney }}</p>
        </li>
      </ul>
    </div>
  </div>
</template>
 
<script>
import { GetChannelDataApi, SearchProductsApi } from "../../request/api";
export default {
  data() {
    return {
      brotherCategory: [],
      currentCategory: [],
      goodsList: [],
      id: [],
      active: "",
    };
  },
  created() {
    GetChannelDataApi({ id: this.$route.params.id }).then((res) => {
      if (res.errno == 0) {
        this.currentCategory = res.data.currentCategory;
        let { brotherCategory } = res.data;
        brotherCategory.map((item, index) => {
          if (item.id == this.$route.params.id) {
            this.active = index;
            console.log(this.active);
          }
        });
        this.brotherCategory = brotherCategory;
      }
    });
    SearchProductsApi({ categoryId: this.$route.params.id }).then((res) => {
      this.goodsList = res.data.goodsList;
      //   console.log(this.goodsList);
    });
  },
  methods: {
    onClick(id) {
      this.$router.push("/details/" + id);
    },
    tabFn(name) {
      console.log(name);
      this.$router.push("/channel/" + this.brotherCategory[name].id);

      GetChannelDataApi({ id: this.$route.params.id }).then((res) => {
        this.currentCategory = res.data.currentCategory;
      });
      SearchProductsApi({ categoryId: this.$route.params.id }).then((res) => {
        if (res.errno == 0) {
          this.goodsList = res.data.goodsList;
          //   console.log(this.detailsArr);
        }
      });
    },
  },
};
</script>
 
<style lang = "less" scoped>
.channel_title {
  text-align: center;
  height: 50px;
  line-height: 50px;
  font-size: 18px;
}
.channel_sub_title {
  text-align: center;
  height: 40px;
  line-height: 40px;
  color: #666;
}
.details_bottom {
  ul {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    li {
      width: 49%;
      position: relative;
      font-size: 14px;
      background-color: #fff;
      margin-bottom: 10px;

      div {
        height: 20px;
        line-height: 20px;
        text-align: center;
        margin-bottom: 15px;
      }
      p {
        height: 20px;
        line-height: 20px;
        text-align: center;
        color: #8b0000;
      }
    }
  }
}
</style>